<%@ page contentType="text/html;charset=UTF-8" language="java"  pageEncoding="UTF-8" %>
<html>
<head>
    <title>表助手</title>
</head>
<body>

列数: <input type="text" id="columnNumber" size="4">&nbsp;&nbsp;&nbsp;&nbsp;
<button onclick="createTable()">确定</button><br/><br/>

<table id="tableId" border="0">
    <tr id="trId"></tr>
</table><br/>
<button onclick="getUrl()">点击获取链接</button><br/>
<input id="publishUrl" type="text" size="60"><br/><br/>

<b>获取表格数据</b><br/>
输入你的链接：<input id="text_link" type="text" size="40"/><button onclick="getTable()">确定</button><br/><br/>

<div id="div1"></div>

<script>
    function getTable() {
        var sendData=document.getElementById("text_link").value;
        sendData=sendData.substring(sendData.indexOf('?')+1);
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp=new XMLHttpRequest();
        } else {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                showData(xmlhttp.responseText);
            }
        }
        xmlhttp.open("POST","getData",true);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=UTF-8");
        xmlhttp.send(sendData);
    }
    function showData(str) {
        var res="<table border='1'>";
        var div1=document.getElementById("div1");
        var count=str.substring(0,str.indexOf(";"));
        str=str.substring(str.indexOf(";")+1);
        var columnNum=str.substring(0,str.indexOf(";"));
        str=str.substring(str.indexOf(";")+1);
        for(var i=0;i<count;i++){
            res+="<tr>";
            for(var j=0;j<columnNum;j++){
                res+="<td width='80' align='center'><h3>"+str.substring(0,str.indexOf(";"))+"</h3></td>";
                str=str.substring(str.indexOf(";")+1);
            }
            res+="</tr>";
        }
        res+="</table>";
        div1.innerHTML=res;
    }
</script>

<script>
    function getUrl() {
        var sendData;
        var userId="0001";
        var userReportId=""+new Date().getTime();
        var reportColumnNumber=document.getElementById("columnNumber").value;
        sendData="user_id=0001"+"&user_report_id="+userReportId+"&report_column_number="+reportColumnNumber;
        for(var i=1;i<=reportColumnNumber;i++){
            sendData+="&t"+i+"="+document.getElementById("t"+i).value;
        }
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp=new XMLHttpRequest();
        } else {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                document.getElementById("publishUrl").value=xmlhttp.responseText;
            }
        }
        xmlhttp.open("POST","getUrl",true);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=UTF-8");
        xmlhttp.send(sendData);
    }
    
    function createTable() {
        var trContent=document.getElementById("trId");
        var str="";
        for(var i=1;i<=(document.getElementById("columnNumber")).value;i++){
            str=str+"<th><input type=\"text\" id=\"t"+i+"\" size=\"4\"></th>";
        }
        trContent.innerHTML=str;
    }
</script>
</body>
</html>
